//替换query的replace-route插件
const addQuery=function(queryData){
    var query={};
    Object.assign(query,this.$route.query,queryData);
    this.$router.replace({
        path:this.$route.path,
        query:query
    });
};
// 删除query
const delQuery=function(){
    var query={};
    var arg=Array.prototype.slice.call(arguments);
    Object.assign(query,this.$route.query);
    arg.forEach(item=>{
        delete query[item];//删除参数
    })
    this.$router.replace({
        path:this.$route.path,
        query:query
    });
};
// 重置query
const resetQuery=function(queryData){
    var query={};
    Object.assign(query,queryData);
    this.$router.replace({
        path:this.$route.path,
        query:query
    });
};
// arg: 保留的参数 queryData: 覆盖的参数
const holdQuery=function(queryData, arg) {
    var query={},
    pre_query = this.$route.query,
    argArr = Array.isArray(arg) ? arg : [];
    argArr.forEach(item=>{
        if (String(pre_query[item]) !== ('undefined' || 'null')) {
            query[item] = pre_query[item]
        }
    })
    Object.assign(query, queryData);
    this.$router.replace({
        path:this.$route.path,
        query:query
    });
};
var install = {
    install(Vue) {
        Vue.mixin({
            beforeCreate() {
                var self=this;
                this.$routePlugin={
                    addQuery:addQuery.bind(self),
                    delQuery:delQuery.bind(self),
                    resetQuery:resetQuery.bind(self),
                    holdQuery: holdQuery.bind(self)
                }
            }
        })
    }
}
export default install;